<template>
	<view class="BlockDownAdd" v-if="show" @click="down()" :class="$isPC ? 'IsPC':''">
		<image src="../../static/logo.png" mode=""></image>
		<view class="left-txt">
			<view class="down">
				<text class="title">转客盟</text>
				<text class="btn">立即下载</text>
			</view>
			<view class="toast">
				更多精彩尽在转客盟APP，赶紧下载吧！
			</view>
		</view>
		<view class="close" @click.stop="close()">
			<text class="iconfont icon-hide-app"></text>
		</view>
	</view>
</template>

<script>
	import {
		appVersion
	} from "@/api/entrance.js"
	import {browserType} from "@/utils/util.js"
	export default {
		name: "BlockDownAdd",
		data() {
			return {
				show: true
			}
		},
		methods: {
			close() {
				this.show = false;
			},
			async down() {
				let type = await browserType();
				let res = await appVersion();
				if (res.code === 1) {
					if(type === "wx"){
						this.$msg("请在浏览器中打开App下载")
					}else{
						let url = res.data.downloadAndroudUrl;
						let dload = document.createElement("a");
						dload.download = '转客盟'; // 设置下载的文件名，默认是'下载'
						dload.href = url;
						document.body.appendChild(dload);
						dload.click();
						dload.remove(); // 下载之后把创建的元素删除
					}
				}
			}
		}
	}
</script>

<style scoped lang="less" src="./BlockDownAdd.less">
</style>
